package com.agv.core.dao.catalogosImpl;

import org.springframework.dao.DataAccessException;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.support.JdbcDaoSupport;
import com.agv.core.dao.catalogos.Cxc_cfg_ttransacDAO;
import com.agv.core.dao.exception.QueryDAOException;

public class Cxc_cfg_ttransacDAOImpl extends JdbcDaoSupport implements Cxc_cfg_ttransacDAO{

	public String getNuDocto() throws QueryDAOException {
		Integer idUltimo;
		try {
			idUltimo = getJdbcTemplate().queryForInt(MAX_SEC_SIG_FACT_SQL);			
		} catch (EmptyResultDataAccessException erdae) {
			return null;
		} catch (DataAccessException dae) {
			throw new QueryDAOException("Error extraer MAX_SEC_SIG_FACT***", dae);
		}
		return idUltimo.toString();
	}
	
	public void updateSec_sig_fact(String sec_sig_fact) throws QueryDAOException {
		try {
			Integer dat= Integer.parseInt(sec_sig_fact) + 1;
			getJdbcTemplate().update(UPDATE_MAX_SEC_SIG_FACT_SQL,
					new Object[] { dat, Integer.parseInt(sec_sig_fact)});
		} catch (DataAccessException dae) {
			throw new QueryDAOException("app.error.actualiza.etapa", dae);
		}
	}
			
	
	private static final String MAX_SEC_SIG_FACT_SQL = "select MAX(sec_sig_fact) from cxc.t001_cxc_cfg_ttransac";
	public static final String UPDATE_MAX_SEC_SIG_FACT_SQL = "UPDATE cxc.t001_cxc_cfg_ttransac SET sec_sig_fact = ? WHERE sec_sig_fact = ?";
	
	
}
